$(function(){
	
	//1、全局token开始,拿到ID
	var url =  window.parent.parent.location.href;
	var token = url.split("token")[1];
	token=token.slice(1);
	console.log("student-manager.html的token="+token);
	//1、全局token结束
	
	//2、解析出上下文逻辑开始 拿到 http://localhost:8080/
	var context = getRootPath();
	console.log("context="+context);
	//2、解析出上下文逻辑结束
	
	
	
	
	
	//3、角色分页列表页面开始
	var vue =new Vue({
		el:'#studentListTable',
		data:{
			student:{
				education: "",
				id: 0,
				name: "",
				phone: "",
				email: "",
				
			},
			userName:"",
			clazzName:"",
			EducationList:"",
		
			
			
		
		
	
		},
		methods:{
			//发送查找个人信息的请求
			getStudentMessage:function(){
				 var url=context+'student/StudentMessage?token='+token;
				 console.log(url)
				
				axios.get(url).then(function(callback){
					console.log(callback);
					var code =callback.data.code;
					var studentList=callback.data.data;
					console.log(studentList);
					vue.student=studentList;
					
					
					
				});
				
			},
			findClassAndTeacherByStudentId:function(){
				 var url=context+'student/findClassAndTeacherByStudentId?token='+token;
				 
				 console.log(url)
				
				axios.get(url).then(function(dataR){
					console.log(dataR);
					var ClassAndTeacher=dataR.data.data;
					vue.clazzName=ClassAndTeacher.clazzBean.name;
					vue.userName=ClassAndTeacher.userBean.name;
				});
				
			},
			
			//模态框展示动作
			tableUpdateStudentButton:function(){
				
				var student = this.student;
				console.log(student);
				
				var id =student.id;
				var studentName=student.name;
				var studentPhone=student.phone;
				var studentEmail=student.email;
				var studentEducation=student.education;
				//1.1：填充表格
				$('p[name="updateStudentId"]').text(id);
				$('input[name="updateStudentId"]').val(id);
				$('input[name="updateStudentName"]').val(studentName);
				$('input[name="updateStudentPhone"]').val(studentPhone);
				$('input[name="updateStudentEmail"]').val(studentEmail);
				
				//循环拿到学历 并塞入option中
				var html = '';
				      for (var i = 0; i <vue.Educations.length; i ++) {
				        html += "<option id="+vue.Educations[i].id+" name='EducationId'>" + vue.Educations[i].dictionary + "</option>";
				      }
				$('#EducationList').append(html);
				
				
				//1.2：打开模态框
				$('#updateStudentModal').modal({
					backdrop:"static",
				});
			},	
			
			//查找所有学历信息
			findEducation:function(){
				var url=context+'/student/findAllDictionary';
				axios.post(url).then(function(dataR){
					console.log(dataR);
					var EducationList=dataR.data.data;
					vue.Educations=EducationList;
				});
			},
		},
		
			
	});
	vue.getStudentMessage();
	vue.findClassAndTeacherByStudentId();
	vue.findEducation();
	//3、角色分页列表页面结束
	
	
	
	
	
	//发送修改学生信息的请求
	//单击编辑角色模块框中的保存按钮 开始-------------------------------------- 
	$('#modalUpdateStudentButton').click(function(){
		
		//2.1:收集表单数据并向后台发送请求
		var id=$("input[name='updateStudentId']").val();
		var studentName=$("input[name='updateStudentName']").val();
		var studentPhone=$("input[name='updateStudentPhone']").val();
		var studentEmail=$("input[name='updateStudentEmail']").val();
		var EducationId=$("#EducationList").find('option:selected').attr('id');

		var data={
			token:token,
			name:studentName,
			phone:studentPhone,
			email:studentEmail,
			education:EducationId,
			
		};
		
		var url=getRootPath()+'student/updateUserMessage';
		var callback=function(dataR){
			var code=dataR.code;
			if(code==200){
				//2.2:关闭修改模态框
				$('#updateStudentModal').modal('hide');
				
				//2.3:刷新刷新页面数据
				vue.getStudentMessage();
				
			};
			
		};
		send(url,data,callback);
	});
	//单击编辑角色模块框中的保存按钮 结束-------------------------------------- 
	
	//发送查找所有学历的请求
	
	

	
	
});
